USE [ANTS_NetServer]
GO

/****** Object:  StoredProcedure [dbo].[proc_paged_with_notin]    Script Date: 04/21/2013 15:27:28 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[proc_paged_with_notin]  --利用select top and select not in 
 ( 
     @pageIndex int,  --页索引 
     @pageSize int    --每页记录数 
 ) 
 as 
 begin 
     set nocount on; 
     declare @timediff datetime --耗时 
    declare @sql nvarchar(500) 
    select @timediff=Getdate() 
    set @sql='select top '+str(@pageSize)+' * from tb_TestTable where(ID not in(select top '+str(@pageSize*@pageIndex)+' id from tb_TestTable order by ID ASC)) order by ID' 
    execute(@sql)  --因select top后不支技直接接参数，所以写成了字符串@sql 
    select datediff(ms,@timediff,GetDate()) as 耗时 
    set nocount off; 
end
GO

